#include <iostream>
using namespace std;

const int N = 2e5 +10; 

int n;
int a[N];

int dfs(int l, int r)
{
	if (l >= r) return a[l];
	
	int mid = (l+r)>>1;
	
	int ret = max(dfs(l, mid), dfs(mid+1, r));
	
	int suml = a[mid], sumr = a[mid+1];
	int maxl = suml, maxr = sumr;
	
	for (int i = mid-1; i >= l; i--)
	{
		suml += a[i];
		maxl = max(maxl, suml);	
	 }	 
	 
	 for (int i = mid+2; i <= r; i++)
	 {
	 	sumr += a[i];
	 	maxr = max(maxr, sumr);
	 }
	 
	 return max(maxr + maxl, ret);
}

int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) cin>> a[i];
	
	cout << dfs(1, n) << endl;
	
	return 0;
 }
